package com.uairobot.bill.freeswitch.controller;

import java.util.List;

import com.jfinal.core.Controller;
import com.jfinal.core.paragetter.Para;
import com.uairobot.bill.freeswitch.model.PhoneNumber;
import com.uairobot.bill.freeswitch.vo.JsonBean;

/**
 * @author bill robot
 * @date 2020年2月21日_下午9:10:15 
 * @version 1.0 
 * @desc
 */
public class PhoneNumberController extends Controller {
  public void add(@Para("") PhoneNumber phoneNumber) {
    boolean save = phoneNumber.save();
    if (save) {
      renderJson(new JsonBean<Void>());
    } else {
      renderJson(new JsonBean<Void>(-1));
    }
  }

  public void list(@Para("") PhoneNumber phoneNumber) {
    List<PhoneNumber> findAll = phoneNumber.findAll();
    JsonBean<List<PhoneNumber>> jsonBean = new JsonBean<>(findAll);
    renderJson(jsonBean);
  }

  public void edit(@Para("") PhoneNumber phoneNumber) {
    boolean update = phoneNumber.update();
    if (update) {
      renderJson(new JsonBean<Void>());
    } else {
      renderJson(new JsonBean<Void>(-1));
    }
  }

  public void del(@Para("") PhoneNumber phoneNumber) {
    boolean deleteById = phoneNumber.deleteById(phoneNumber.getId());
    if (deleteById) {
      renderJson(new JsonBean<Void>());
    } else {
      renderJson(new JsonBean<Void>(-1));
    }
  }
}
